@extends('../manage.layout')
@section('content')
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            内容管理
            <small></small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
            <li class="active">Here</li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <form action="/manage/artibatcserc/" method="post" id="form">{{ csrf_field() }}
                <!-- general form elements -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <a href="javascript:batchdelSub()"><span class="btn btn-danger">批量删除</span></a> <a href="/manage/article/create" type="submit" class="btn btn-success"><i class="fa fa-pencil"></i> 添加文章</a>
                    </div>
                    <!-- table start -->
                    <div class="row">

                        <div class="col-xs-12">
                            <div class="box">
                                <div class="box-header">
                                    <h3 class="box-title">文章列表</h3>

                                    <div class="box-tools">
                                        <div class="input-group input-group-sm" style="width: 150px;">
                                            <select class="form-control pull-right"  name="category" id="category" style="position:absolute; right:410px;">
                                                <option value="">请选择</option>
                                                @foreach($categorys as $category)
                                                    <option value="{{ $category->id }}">{{ $category->name }}</option>
                                                @endforeach
                                            </select>
                                            <input type="text" name="create_time" class="form-control pull-right" id="reservation" style="position:absolute; right: 296px;" value="">
                                            <input type="text" name="keyword" class="form-control pull-right" placeholder="关键词" style="position:absolute; right:148px">
                                            <input type="text" name="table_search" class="form-control pull-right" placeholder="标题">

                                            <div class="input-group-btn">
                                                <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- /.box-header -->
                                <div class="box-body table-responsive no-padding">
                                    <table class="table table-hover" id="table">
                                        <tr>
                                            <th><input type="checkbox" value="" onclick="selectAll(this)"></th>
                                            <th>ID(权重)</th>
                                            <th>标题</th>
                                            <th>分类</th>
                                            <th>关键词</th>
                                            <th>导读图</th>
                                            <th>创建时间</th>
                                            <th>更新时间</th>
                                            <th>操作</th>
                                        </tr>
                                        <script>
                                            function selectAll(obj) {
                                                $("#table input[type='checkbox']").prop('checked', $(obj).prop('checked'));
                                            }
                                        </script>
                                        @foreach($articles as $article)
                                            <tr>
                                                <td><input name="chkbox[]" type="checkbox" value="{{ $article->id }}"></td>
                                                <td>{{ $article->id }} ({{ $article->rank }})</td>
                                                <td>{{ $article->title }}</td>
                                                @foreach($categorys as $category)
                                                    @if($article->category == $category->id)
                                                        <td>{{ $category->name }}</td>
                                                    @endif
                                                @endforeach
                                                <td>{{ $article->keyword }}</td>
                                                <td><a href="/upload/{{ $article->file }}" target="_blank"><img src="/upload/{{ $article->file }}" width="30" height="30" /></a></td>
                                                <td>{{ $article->create_time }}</td>
                                                <td>{{ $article->update_time }}</td>
                                                <td width="240">
                                                    @if($article->status == 1)
                                                        <a href="/manage/article/{{ $article->id }}"><span class="label label-success">启用</span></a>
                                                    @else
                                                        <a href="/manage/article/{{ $article->id }}"><span class="label bg-orange">禁用</span></a>
                                                    @endif
                                                        &nbsp;
                                                    <a href="/manage/article/{{ $article->id }}/edit"><span class="label label-primary">更改</span></a>&nbsp;
                                                    {{--<a href="/manage/article/seo/{{ $article->id }}/edit"><span class="label label-primary">设置seo</span></a>&nbsp;--}}
                                                    <a href="javascript:delSubscribe({{ $article->id }})"><span class="label label-danger">删除</span></a></td>
                                            </tr>
                                        @endforeach
                                    </table>
                                </div>
                                <!-- /.box-body -->
                            </div>
                            <!-- /.box -->
                        </div>

                    </div>
                    <!-- /.table -->
                    <div style="text-align: center">{{ $articles->links() }}</div>

                </div>
                </form>
            </div>
        </div>
    </section>
    <!-- /.content -->
@endsection
@section('script')
    <script type="text/javascript">
        $('#reservation').daterangepicker();
    </script>
@endsection
<script>
    function delSubscribe(id) {
        layer.confirm('删除不可恢复，是否继续？', {
            btn:['确定','取消'] //按钮
        }, function() {
            $.post("{{ url('manage/article/') }}/"+id,{'_method':'delete','_token':"{{ csrf_token() }}"},function(data){
                if(data.status==0) {
                    layer.msg(data.msg, {time:1500, icon:5, end:function(){location.reload();}});
                } else {
                    layer.msg(data.msg, {time:1500, icon:6, end:function(){location.reload();}});
                    //window.location.href = "/manage/article/";
                }
            });
        }, function() {

        });
    }

    function batchdelSub() {
        /*var data = [];
         var ckb = document.getElementsByName('chkbox[]');
         for(var i = 0; i < ckb.length; i++) {
         if(ckb[i].checked) {
         data.push(ckb[i].value);
         }
         }*/
        layer.confirm('删除不可恢复，是否继续？', {
            btn:['确定','取消'] //按钮
        }, function() {
            $.ajax({
                url: "/manage/artibatcdel/",
                type: "POST",
                data: $('#form').serialize(),
                success: function (data) {
                    layer.msg(data.msg, {time:1500, icon:6, end:function(){location.reload();}});
                },
                error: function (data) {
                    layer.msg(data.msg, {time:1500, icon:5, end:function(){location.reload();}});

                }
            });
        });
    }

    function batchExport() {
        $.ajax({
            url: "/manage/aritbatcexport/",
            type: "POST",
            data: $('#form').serialize(),
            success: function (data) {
                if(data.code == 404) {
                    layer.msg(data.msg, {
                        time: 1500, icon: 5
                    });
                }
                else {
                    layer.msg(data.msg, {
                        time: 1500, icon: 6, end: function () {
                            location.reload();
                        }
                    });
                }
            },
            error: function (data) {
                layer.msg('ajax交互失败', {
                    time: 1500, icon: 6
                });
            }
        });
    }


</script>















{{--            var chkbox = [];
            var ckb = document.getElementsByName('chkbox[]');
            for(var i = 0; i < ckb.length; i++) {
                if(ckb[i].checked) {
                    chkbox.push(ckb[i].value);
                }
            }

            $.ajax({
                type:"POST",
                url:"/manage/artibatcdel/",
                data:{"chkbox":chkbox},
                traditional:true,
                success:function(data) {
                    alert(data.msg);
                }
            });--}}

